package com.itheima.dianming.listener;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.dianming.pojo.domain.StuInterfaceTestLog;
import com.itheima.dianming.service.StuInterfaceTestLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RabbitMQListener {


    @Autowired
    private StuInterfaceTestLogService logService;

    @RabbitListener(queues = "queue.project.log")
    public void saveTestLog(StuInterfaceTestLog testLog){
        log.info("开始记录日志：{}",testLog);
        LambdaQueryWrapper<StuInterfaceTestLog> qw = new LambdaQueryWrapper<>();
        qw.eq(StuInterfaceTestLog::getProjectId,testLog.getProjectId());
        qw.eq(StuInterfaceTestLog::getStep,testLog.getStep());
        qw.eq(StuInterfaceTestLog::getStuId,testLog.getStuId());
        StuInterfaceTestLog one = logService.getOne(qw);
        if(one!=null){
            testLog.setId(one.getId());
            logService.updateById(testLog);
        }else {
            logService.save(testLog);
        }
    }
}
